package com.itstyle.mytest.threadpoolexecutor;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author xianguang
 * @date 2020-01-06 17:09
 */
public class TestAtomicInteger {
    //public static AtomicInteger num=new AtomicInteger(0);
    static AtomicInteger num=new AtomicInteger(0);
    static final  int taskNum=200000;
    public static void main(String[] args) throws InterruptedException {

        CountDownLatch latch=new CountDownLatch(taskNum);
        for (int i = 0; i <taskNum ; i++) {
            new Thread(()->{
                num.getAndIncrement();
                latch.countDown();
            }).start();
        }
        latch.await();


        System.out.println(num);
    }
}
